#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.67])
AC_INIT([despotify], [1.0], [BUG-REPORT-ADDRESS])
CFLAGS=""
AM_INIT_AUTOMAKE(despotify, 1.0)
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_LIBTOOL

PKG_PROG_PKG_CONFIG

# Checks for libraries.
# FIXME: Replace `main' with a function in `-lcrypto':
AC_CHECK_LIB([crypto], [main])
# FIXME: Replace `main' with a function in `-leay32':
AC_CHECK_LIB([eay32], [main])
# FIXME: Replace `main' with a function in `-lvorbisfile':
AC_CHECK_LIB([vorbisfile], [main])
# FIXME: Replace `main' with a function in `-lz':
AC_CHECK_LIB([z], [main])

AC_CHECK_LIB([resolv], [main])

# Checks for header files.
AC_HEADER_RESOLV
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h locale.h netdb.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h unistd.h wchar.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_CHECK_FUNCS([gethostbyname gettimeofday memchr memmove memset mkdir munmap select setlocale socket strchr strcspn strdup strncasecmp strspn strstr strtol])

AC_ARG_ENABLE(simple,
	AS_HELP_STRING([--enable-simple],
		[build the simple client]),en_simple=$enableval,
	[en_simple=no])

AC_ARG_ENABLE(gateway,
	AS_HELP_STRING([--enable-gateway],
		[build the gateway client]),en_gateway=$enableval,
	[en_gateway=no])
	
AC_ARG_ENABLE(despotify,
	AS_HELP_STRING([--enable-despotify],
		[build the despotify client]),en_despotify=$enableval,
	[en_despotify=no])

AC_ARG_ENABLE(maemify,
	AS_HELP_STRING([--enable-maemify],
		[build maemify client]),en_maemify=$enableval,
	[en_maemify=no])
	
AC_ARG_ENABLE(ao,
	AS_HELP_STRING([--enable-libao],
		[enable libao backend]),en_libao=$enableval,
	[en_libao=no])
	
OS=`uname -s`
if test x$en_gateway = xyes || test x$en_simple = xyes || test x$en_despotify = xyes; then
	echo "client en"
	if test $OS = Darwin; then
		osx=yes
		en_libao=no
	else
		osx=no
		en_libao=yes
		AC_CHECK_LIB([ao], [main])
	fi
fi

if test x$en_simple = xyes ;then	
	AC_CHECK_LIB([pthread], [main])
fi

if test x$en_despotify = xyes; then
	AC_CHECK_LIB([ncursesw], [main])
fi

if test x$en_maemify = xyes; then
	AC_CHECK_LIB([gtk2], [main])
fi

#todo detect if the host is maemo4
AM_CONDITIONAL(MAEMO4, false)
AC_DEFINE([MAEMO4], 0, [Build the despotify client])

AM_CONDITIONAL(OSX, test x$osx = xyes)

AM_CONDITIONAL(LIBAO, test x$en_libao = xyes)
AM_CONDITIONAL(SIMPLE, test x$en_simple = xyes)
AM_CONDITIONAL(GATEWAY, test x$en_gateway = xyes)
AM_CONDITIONAL(DESPOTIFY, test x$en_despotify = xyes)

AM_CONDITIONAL(MAEMIFY, test x$en_maemify = xyes)

AC_CONFIG_FILES([Makefile
								 lib/Makefile
								 clients/Makefile
								 clients/simple/Makefile
								 clients/gateway/Makefile
								 clients/despotify/Makefile
 								 clients/maemify/Makefile
])

AC_OUTPUT
